<template>
  <div class="page">
    <headerbar>重置密码</headerbar>
    <section class="pdh-4 pdv-2">
      <div class="pdv-5"></div>

      <div class="input-column-wrap">
      <div class="input-wrap">
        <input type="password" placeholder="请输入新密码（8-18位字母+数字+特殊符号组合）" v-model="newPwd">
      </div>
      </div>
      <div class="input-column-wrap">
      <div class="input-wrap">
        <input type="password" placeholder="请再次输入密码" v-model="confirmPwd">
      </div>
      </div>

      <div class="pdv-3"></div>
      <div @click="save()" class="default-block-btn">确认</div>
    </section>
  </div>
</template>

<script>
  import tools from '@/utils/tools'
  import api from '@/common/config/api'
  import loginService from '@/service/loginService'
  export default {
    name: '',
    data () {
      return {
        fn: tools,
        newPwd: '',
        confirmPwd: '',
        uuid: ''
      }
    },
    created () {
      this.uuid = this.$route.params.uuid
    },
    methods: {
      save () {
        if (this.newPwd === '') {
          return tools.alert('请输入新密码')
        }
        if (this.confirmPwd === '') {
          return tools.alert('请输入新密码')
        }
        if (this.newPwd !== this.confirmPwd) {
          return tools.alert('两次密码不一致')
        }
        let data = {
          uuid: this.uuid,
          password: this.confirmPwd
        }
        loginService.updatePassWordByPhone(data).then((res) => {
          if (res.code === 0) {
            tools.tip(res.message||'密码修改成功！');
            setTimeout(()=>{
              this.loginOut()
            },1000);
          } else {
            // this.loginOut()
            tools.alert(res.message)
          }
        })
      },
      loginOut () {
        this.$localStorage.set('password',this.newPwd);
        this.$localStorage.set('forgetPwd',this.newPwd);
        this.$localStorage.remove('userInfo');
        this.$router.replace({name: 'login',params:{type:'setPwd'}})
      }
    }
  }
</script>

<style scoped lang="scss">
  .setup-input {
    height: 40px !important;
  }
  .mui-table-view {
    font-size: 14PX;
    .mui-table-view-cell {
      padding: 15px 30px;
    }
  }
</style>
